package com.fpd.model.bean;

import java.util.Date;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fpd.model.ro.PageRO;
import com.fpd.tools.Tool;

/**
 * @desc 日志类-记录用户操作行为
 * @author wujiangbo
 * @date 2019年11月15日 上午10:43:11
 */
public class Log extends PageRO {

	private static final long serialVersionUID = -7237976532878596055L;

	private String log_id; // 日志主键

	private String type; // 日志类型

	private String title; // 日志标题

	private String remote_addr; // 请求地址

	private String request_uri; // URI

	private String method; // 请求方式

	private String params; // 请求参数

	private String exception; // 异常

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date operateDate; // 操作时间

	private String timeout; // 结束时间

	private String user_id; // 用户ID

	private String result_params;// 返回参数

	public String getLogId() {
		return log_id;
	}

	public void setLogId(String log_id) {
		this.log_id = log_id;
	}

	public String getResultParams() {
		return result_params;
	}

	public void setResultParams(String result_params) {
		this.result_params = result_params;
	}

	public String getType() {
		return Tool.isBlank(type) ? type : type.trim();
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTitle() {
		return Tool.isBlank(title) ? title : title.trim();
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getRemoteAddr() {
		return Tool.isBlank(remote_addr) ? remote_addr : remote_addr.trim();
	}

	public void setRemoteAddr(String remote_addr) {
		this.remote_addr = remote_addr;
	}

	public String getRequestUri() {
		return Tool.isBlank(request_uri) ? request_uri : request_uri.trim();
	}

	public void setRequestUri(String request_uri) {
		this.request_uri = request_uri;
	}

	public String getMethod() {
		return Tool.isBlank(method) ? method : method.trim();
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getParams() {
		return Tool.isBlank(params) ? params : params.trim();
	}

	public void setParams(String params) {
		this.params = params;
	}

	/**
	 * 设置请求参数
	 *
	 * @param paramMap
	 */
	public void setMapToParams(Map<String, String[]> paramMap) {
		if (paramMap == null) {
			return;
		}
		StringBuilder params = new StringBuilder();
		for (Map.Entry<String, String[]> param : paramMap.entrySet()) {
			params.append(("".equals(params.toString()) ? "" : "&") + param.getKey() + "=");
			String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
			params.append(Tool.abbr(StringUtils.endsWithIgnoreCase(param.getKey(), "password") ? "******" : paramValue, 100));
		}
		String pa = params.toString();
		if (!Tool.isBlank(pa) && pa.length() > 255) {
			pa = pa.substring(0, 251);
		}
		this.params = pa;
	}

	public String getException() {
		return Tool.isBlank(exception) ? exception : exception.trim();
	}

	public void setException(String exception) {
		this.exception = exception;
	}

	public Date getOperateDate() {
		return operateDate;
	}

	public void setOperateDate(Date operateDate) {
		this.operateDate = operateDate;
	}

	public String getTimeout() {
		return Tool.isBlank(timeout) ? timeout : timeout.trim();
	}

	public void setTimeout(String timeout) {
		this.timeout = timeout;
	}

	public String getUserId() {
		return user_id;
	}

	public void setUserId(String user_id) {
		this.user_id = user_id;
	}
}
